Tanmay Teaches Go by Tanmay Bakshi

Tanmay Teaches Go by Tanmay Bakshi

Author:Tanmay Bakshi [Bakshi, Tanmay]
Language: eng
Format: epub
Publisher: McGraw-Hill Education
Published: 2021-10-15T00:00:00+00:00


This first section starts by creating the cost and parent (dist and prev) dictionaries and initializes them in the way that was described at the beginning of the chapter. The costs are all infinite and the parents are all nil. (In this case, nil is represented as an empty string, because the value is not a pointer.) We also create the dictionary that represents whether or not a node has been visited, and we set the distance, which is the cost, for the source node to 0.

This section of the code has one simple responsibility: start a for loop with the variable u that starts with the source string, and then loops until the u variable is equal to an empty string. After every iteration, call the getClosestNonVisitedNode function, pass it the dictionaries it needs, and store the result in u. The logic behind this line is that when this function returns an empty string, we’ve already visited all the nodes and can stop the loop.

After we start the loop itself, we simply query the cost and distance dictionary for the node that we’re on and store that distance in uDist.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.